<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>康纳天花系统后台</title>
<link href="/css/bootstrap.min.css" rel="stylesheet" type="text/css">
<link href="/css/admins/base.css" rel="stylesheet" type="text/css">
<link href="/css/plugs/jDatepicker/jDatepicker-min.css"  rel="stylesheet"  /> 
<script src="/js/plugs/jquery.js"></script>

<script src="/js/admins/base.js"></script>
<script src="/js/plugs/jDatepicker/jDatepicker-min.js"></script>
<script src="/js/plugs/global.js"></script>
<script src="/js/admins/salesman_manage.js"></script>
<script src="/js/layer/layer.js"></script>
<style type="text/css" >
    {#$pageCss#}
	
	
.ebtr{
	width:445px;
	margin:0 auto;
	margin-top:20px;
	border-collapse:separate; 
	border-spacing:0 20px;
}
.ebtr tr{
	height:45px;
}
.ebtr_l{
	width:100px;
	height:45px;
	text-align:center;
}

.ebtr_r{
	width:345px;
	height:45px;
}
.ebtr_r select,.ebtr_r input{
	width:345px;
	height:45px;
	line-height:45px;
}
.ebtr_r input#addebookbtn{
	width:100px;
	height:35px;
	line-height:35px;
	color: #fff;
	border:none;
    background-color: #f0ad4e;
    border-color: #eea236;
	text-align:center;
}

.file {
    position: relative;
    display: inline-block;
    background: #D0EEFF;
    border: 1px solid #99D3F5;
    overflow: hidden;
    color: #1E88C7;
    text-decoration: none;
	width:345px;
	height:45px;
	line-height:45px;
	text-align:center;
}
.file input {
    position: absolute;
    left: 0;
    top: 0;
    opacity: 0;
}
.file:hover {
    background: #AADFFD;
    border-color: #78C3F3;
    color: #004974;
    text-decoration: none;
}

</style>
</head>

<body>

<!-- nav start-->
{# include file="$tpl_root_path/admins/base/navbar.html" #}
<!-- nav end -->    
    
    
    
    
<div class="container-fluid">
    
      <div class="row">
      
    <!-- left  box start-->     
       {# include file="$tpl_root_path/admins/base/left_menu.html" #}
    <!-- left  box end-->        
 
  <!-- right  box start-->  
         
     <div class="col-sm-9 col-sm-offset-3 col-md-10 col-md-offset-2 main right-box">
          
          <div class="menu-navbar">{#$menu_navbar#}</div>
          <h3 class="page-header">内容管理 </h3>


          
          <div class="tool-list-box">
              <a href="javascript:;" onclick="return false;" target="_blank" id="addebook" class="btn btn-warning">新增电子书</a>
          </div>
          
          <div class="info-list-box">
          <table class="table table-hover">
              <thead>
                <tr>
                  <th>名称</th>
				  <th>排序</th>
				  <th>日期</th>
                  <th>状态</th>
				  <th>操作</th>
                </tr>
              </thead>
              <tbody>

              {#if $list#}
              {#foreach from=$list item=i#}

                <tr>
				  <td class="showname" lang="{#$i.PATH#}" style="cursor:pointer;">{#$i.NAME#}</td>
				  <td class="orders" lang="{#$i.ID#}">{#$i.LANGUAGE#}</td>
                  <td>{#$i.DATELINE|date_format:'%Y-%m-%d %H:%M:%S'#}</td>
				  <td>{# if $i.STATUS eq 2#}<span style="color:green;">已上架</span>{#else#}<span style="color:red;">已下架</span>{#/if#}</td>
                  <td><a href="javascript:;" onclick="changeStatus('{#$i.ID#}','{#$i.STATUS#}')">{# if $i.STATUS eq 2#}下架{#else#}上架{#/if#}</a></td>
                      
                </tr>

              {#/foreach#}
              {#else#}
              <tr class="tab_list_tr">
                  <td colSpan="6" style="text-align:center;">
                      {#$nodatainfo#}
                  </td>
              </tr>
              {#/if#}

                
              </tbody>
            </table>
          </div>

         <div  id="pages">
             {#$pageform#}
         </div>

          
     </div>
 
  <!-- right  box end-->         
        
      </div>
</div>



</body>
</html>

<script type="text/javascript">

$("#addebook").click(function(){
	layer.open({
	  type: 1,
	  title:['新增电子书','text-align:center;font-size:18px;'],
	  skin: 'layui-layer-rim', //加上边框
	  area: ['560px', '370px'], //宽高
	  content: '<form method="post" action="/admins/book_manage-cmd-add.html" enctype="multipart/form-data"><table class="ebtr"><tr><td class="ebtr_l">选择图片</td><td class="ebtr_r"><a href="javascript:;" class="file" ><span class="imgbrief">+添加图片</span><input type="file" name="addfile" id="addfile" onchange="addimg();"></a></td></tr><tr><td class="ebtr_l">名称</td><td class="ebtr_r"><input type="text" name="name"></td></tr><tr><td class="ebtr_l">排序</td><td class="ebtr_r"><input type="text" name="language"></td></tr><tr><td class="ebtr_l"></td><td class="ebtr_r"><input type="submit" id="addebookbtn" value="保存"></td></tr></table></form>'
	});
});
function addimg(){
	var filePath=$('#addfile').val();
	console.log($('#addfile'));
	if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("jpeg")!=-1 || filePath.indexOf("gif")!=-1 || filePath.indexOf("png")!=-1){
		 filePath = filePath.substr(-10,10);
		 filePath = '+添加图片('+filePath+')';
		$(".imgbrief").html(filePath);
	}else{
		layer.msg('您未上传文件，或者您上传文件类型有误');
		return false 
	}

}
$(function(){
	$(".showname").click(function(){
		var path = $(this).attr("lang");
		layer.open({
		  type: 1, 
		  area: ['500px', '295px'],
		  content: '<img src="'+path+'" width="500" height="250" />'
		});
	});
	/*
	$(document).on('change','#addfile',function(){
		var filePath=$(this).val();
		if(filePath.indexOf("jpg")!=-1 || filePath.indexOf("jpeg")!=-1 || filePath.indexOf("gif")!=-1 || filePath.indexOf("png")!=-1){
			/*$(".fileerrorTip").html("").hide();
			var arr=filePath.split('\\');
			var fileName=arr[arr.length-1];
			$(".showFileName").html(fileName);*
		}else{
			layer.msg('您未上传文件，或者您上传文件类型有误');
			return false 
		}
	});
	*/
	
	$(".orders").click(function(){
		var td = $(this);
		var txt = td.text();
		var inp = $("<input type='text'value='" + txt + "'/>"); 
		td.html(inp);
		inp.click(function(){
			return false;
		})
		inp.trigger('focus');
		inp.blur(function(){
			var newtxt = $(this).val();
			if(newtxt != txt){
				td.html(newtxt);
				var id = td.attr("lang");
				var url = "/admins/book_manage-cmd-changeOrder-id-"+id+"-order-"+newtxt+".html";
				$.get(url,function(data){
					if(data==1){
						layer.msg('修改成功!');
					}else{
						layer.msg('修改失败，请重试!');
						td.html(txt); 
					}
				})
			}else{
				td.html(txt); 
			}
		});
	});
});


function changeStatus(id,status){

	var id =id;
	if (typeof id == 'undefined'){
		return false;
	}

	if(confirm('您确定要修改状态吗？')){
		
		 $.ajax({
				type:"POST",
				url:"http://system.gzcanr.com/admins/book_manage-cmd-changeStatus.html",
				data:{'id':id,'status':status},
				//dataType:"json",
				success:function(data){
					if (data == 1) {
						layer.msg('修改成功！');
						document.location.reload();
					}else if(data == 2){
						layer.msg('修改失败！');
					}else {
						layer.msg('修改失败！');
					}
				}
			});
	}

}




</script>